import React, { Component } from "react";
import Counter from "./Counter";
import Button from "./Button";
export default class App extends Component {
  constructor() {
    super();
    this.state = {
      counter: 0,
      step: 2,
    };
  }

  render() {
    return (
      <div>
        {/* counter 组件作为数据的渲染 */}
        <Counter counter={this.state.counter}></Counter>
        {/* button组件作为数据的动态交互 */}
        <Button click={() => this.increment()}></Button>
      </div>
    );
  }

  increment() {
    this.setState((state) => {
      return {
        counter: (state.counter += state.step),
      };
    });
  }
}
